package com.demo.proxy;

import com.demo.proxy.service1.Car;
import com.demo.proxy.service1.CarHandler;
import com.demo.proxy.service1.baoma;
import com.demo.reflect.po.Student;
import org.junit.jupiter.api.Test;
import sun.misc.ProxyGenerator;

import java.io.File;
import java.io.FileOutputStream;
import java.lang.reflect.Proxy;

/**
 * @description:
 * @className: ProxyTest1
 * @package: com.demo.proxy
 * @author: dongww@hsyuntai.com
 * @date: 2019/4/3 16:57
 * @copyright: 版权归 HSYUNTAI 所有
 */
public class ProxyTest1 {

    public static void main(String[] args) {

        try {
            Car car = (Car) Proxy.newProxyInstance(Car.class.getClassLoader(), new Class<?>[] {Car.class}, new CarHandler(new baoma()));
            car.drive("jin", "baoma");
//            car.stop("jin", "baoma");

//            byte[] bs = ProxyGenerator.generateProxyClass("TestImpl", new Class<?>[] {Car.class});
//            new FileOutputStream(new File("d:/TestImpl.class")).write(bs);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
